package gui;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import Controlador.Controlador;
import Controlador.ControladorCliente;
import beans.Cliente;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ModificarClienteFrame extends Vista {
	
	{
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JFrame ventana = new JFrame();
	Cliente cliente;
	
	

	public static void main(String[] args) {
		ModificarClienteFrame m = new ModificarClienteFrame();
		Controlador cli=new ControladorCliente(m);
		m.addControladorCliente(cli);
		
	} 
	

	public ModificarClienteFrame()
	{
		super();
		initGUI();
	}
	
	
	private void initGUI() {
		try {
			{
				jPanel1 = new JPanel();
				ventana.getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setLayout(null);
				jPanel1.setPreferredSize(new java.awt.Dimension(454, 184));
				{
					lblRazonSoc = new JLabel();
					jPanel1.add(lblRazonSoc);
					lblRazonSoc.setText("Razon Social:");
					lblRazonSoc.setBounds(12, 32, 106, 16);
				}
				{
					txtRazonSoc = new JTextField();
					jPanel1.add(txtRazonSoc);
					txtRazonSoc.setBounds(136, 30, 163, 20);
				}
				{
					btnBuscarProveedor = new JButton();
					jPanel1.add(btnBuscarProveedor);
					btnBuscarProveedor.setText("Buscar ");
					btnBuscarProveedor.setBounds(317, 27, 117, 26);
					btnBuscarProveedor.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							btnBuscarProveedorActionPerformed(evt);
						}
					});
				}
				
				{
					btnModificar = new JButton();
					jPanel1.add(btnModificar);
					btnModificar.setText("Modificar Proveedor");
					btnModificar.setBounds(55, 170, 149, 26);
					btnModificar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							btnModificarActionPerformed(evt);
						}
					});
				}
				{
					btnCancelar = new JButton();
					jPanel1.add(btnCancelar);
					btnCancelar.setText("Cancelar");
					btnCancelar.setBounds(224, 170, 119, 26);
					btnCancelar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							btnCancelarActionPerformed(evt);
						}
					});
				}
				{
					lblIdCliente = new JLabel();
					jPanel1.add(lblIdCliente);
					lblIdCliente.setText("ID Cliente:");
					lblIdCliente.setBounds(12, 73, 76, 16);
				}
				{
					txtIdCliente = new JTextField();
					jPanel1.add(txtIdCliente);
					txtIdCliente.setBounds(136, 71, 163, 20);
					txtIdCliente.setEnabled(false);
				}
				ventana.setTitle("Modificar Cliente");
				ventana.setLocationRelativeTo(null);
				ventana.setVisible(true);
				ventana.pack();
				ventana.setSize(470, 253);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	private void btnBuscarProveedorActionPerformed(ActionEvent evt) {
		Cliente cli =((ControladorCliente)getControladorCliente()).buscarCliente(txtRazonSoc.getText());
		cliente = cli;
		txtIdCliente.setText(String.valueOf(cli.getId())); 
		//txtCondCompra.setText(cli.getCondicionCompra());
	}
	
	private void btnModificarActionPerformed(ActionEvent evt) {
	((ControladorCliente)getControladorCliente()).modificarCliente((int)cliente.getId(), txtRazonSoc.getText());		
	}

	
	private void btnCancelarActionPerformed(ActionEvent evt) {
		this.ventana.dispose();
	}
	private JPanel jPanel1;
	private JButton btnCancelar;
	private JTextField txtIdCliente;
	private JLabel lblIdCliente;
	private JButton btnModificar;
	private JTextField txtCondCompra;
	private JButton btnBuscarProveedor;
	private JTextField txtRazonSoc;
	private JLabel lblRazonSoc;

}
